package com.nulldev.util.web.YouTubeExtractor.extractors.util;

import static com.nulldev.util.data.Arrays.maps.FastMaps.fixedUniMap;
import static com.nulldev.util.web.YouTubeExtractor.extractors.util.SharedExtractorUtil.IOS_CLIENT_VERSION;
import static com.nulldev.util.web.YouTubeExtractor.extractors.util.SharedExtractorUtil.IOS_CREATOR_CLIENT_VERSION;
import static com.nulldev.util.web.YouTubeExtractor.extractors.util.SharedExtractorUtil.IOS_MUSIC_CLIENT_VERSION;

import java.util.Collections;
import java.util.Map;

import com.nulldev.util.web.URLUtils.URLUtils;
import com.nulldev.util.web.YouTubeExtractor.YouTubeExtractorConstants;
import com.nulldev.util.web.YouTubeExtractor.baltimore.BaltimoreType;
import com.nulldev.util.web.YouTubeExtractor.baltimore.BaltimoreUserAgent;

public enum YTIAPIClientType {

	/*
	 * Data provided from https://github.com/zerodytrash/yt-dlp/blob/
	 * e3953be6a5e698c0b4197d4c5e91064d0b5f39ea/yt_dlp/extractor/youtube.py (and
	 * https://github.com/zerodytrash/YouTube-Internal-Clients)
	 */

	/* youtube.com */

	WEB("CLIENT_WEB", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "WEB" },
			{ "SYSTEM_FALLBACK_VERSION", "2.20220802.00.00" },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" },
			{ "SYSTEM_OS_NAME", "WINDOWS" } })),
	EMBEDDED_WEB("CLIENT_WEB_EMBEDDED", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "WEB_EMBEDDED_PLAYER" },
			{ "SYSTEM_FALLBACK_VERSION", "1.20220731.00.00" },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "56" },
			{ "SYSTEM_IS_EMBEDDED_CONTEXT", "1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" },
			{ "SYSTEM_OS_NAME", "WINDOWS" } })),
	WEB_YT_MUSIC("CLIENT_YT_MUSIC_WEB", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "WEB_REMIX" },
			{ "SYSTEM_FALLBACK_VERSION", "1.20220727.01.00" },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "67" },
			{ "SYSTEM_CUSTOM_HOST", "music.youtube.com" },
			{ "SYSTEM_FALLBACK_API_KEY", "AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" },
			{ "SYSTEM_OS_NAME", "WINDOWS" } })),
	WEB_YT_CREATOR("CLIENT_YT_CREATORS_WEB", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "WEB_CREATOR" },
			{ "SYSTEM_FALLBACK_VERSION", "1.20220726.00.00" },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "62" },
			{ "SYSTEM_REQUIRES_SAPI_HASH", "1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" },
			{ "SYSTEM_CUSTOM_HOST", "www.youtube.com" },
			{ "SYSTEM_FALLBACK_API_KEY", "AIzaSyBUPetSUmoZL-OhlxA7wSac5XinrygCqMo" },
			{ "SYSTEM_OS_NAME", "WINDOWS" } })),
	WEB_STUDIO("CLIENT_YT_STUDIO_WEB", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "WEB_CREATOR" },
			{ "SYSTEM_CLIENT_NAME", "62" },
			{ "SYSTEM_FALLBACK_VERSION", "1.20220726.00.00" },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "1" },
			{ "SYSTEM_CUSTOM_HOST", "studio.youtube.com" },
			{ "SYSTEM_REQUIRES_SAPI_HASH", "1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" },
			{ "SYSTEM_OS_NAME", "WINDOWS" } })),

	WEB_UNPLUGGED("CLIENT_WEB_UNPLUGGED", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "WEB_UNPLUGGED" },
			{ "SYSTEM_FALLBACK_VERSION", "1.20220325" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" },
			{ "SYSTEM_OS_NAME", "WINDOWS" } })),
	WEB_EXPERIMENTS("CLIENT_WEB_EXPERIMENTS", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "WEB_EXPERIMENTS" },
			{ "SYSTEM_FALLBACK_VERSION", "1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" },
			{ "SYSTEM_OS_NAME", "WINDOWS" } })),
	WEB_HEROES("CLIENT_WEB_HEROES", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "WEB_HEROES" },
			{ "SYSTEM_FALLBACK_VERSION", "0.1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" },
			{ "SYSTEM_OS_NAME", "WINDOWS" } })),
	WEB_UNPLUGGED_ONBOARDING("CLIENT_WEB_UNPLUGGED_ONBOARDING", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "WEB_UNPLUGGED_ONBOARDING" },
			{ "SYSTEM_FALLBACK_VERSION", "0.1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" },
			{ "SYSTEM_OS_NAME", "WINDOWS" } })),
	WEB_UNPLUGGED_OPS("CLIENT_WEB_UNPLUGGED_OPS", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "WEB_UNPLUGGED_OPS" },
			{ "SYSTEM_FALLBACK_VERSION", "0.1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" },
			{ "SYSTEM_OS_NAME", "WINDOWS" } })),
	WEB_UNPLUGGED_PUBLIC("CLIENT_WEB_UNPLUGGED_PUBLIC", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "WEB_UNPLUGGED_PUBLIC" },
			{ "SYSTEM_FALLBACK_VERSION", "0.1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" },
			{ "SYSTEM_OS_NAME", "WINDOWS" } })),

	WEB_INTERNAL_ANALYTICS("CLIENT_WEB_INTERNAL_ANALYTICS", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "WEB_INTERNAL_ANALYTICS" },
			{ "SYSTEM_FALLBACK_VERSION", "0.1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" },
			{ "SYSTEM_OS_NAME", "WINDOWS" } })),

	WEB_PARENT_TOOLS("CLIENT_WEB_PARENT_TOOLS", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "WEB_PARENT_TOOLS" },
			{ "SYSTEM_FALLBACK_VERSION", "1.20220325" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" },
			{ "SYSTEM_OS_NAME", "WINDOWS" } })),

	WEB_PHONE_VERIFICATION("CLIENT_WEB_PHONE_VERIFICATION", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "WEB_PHONE_VERIFICATION" },
			{ "SYSTEM_FALLBACK_VERSION", "1.0.0" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" }, })),

	/* Android */

	ANDROID("CLIENT_ANDROID_YT", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "ANDROID" },
			{ "SYSTEM_ENABLE_BALTIMORE_V1", BaltimoreType.YOUTUBE_APP.id() },
			{ "SYSTEM_FALLBACK_VERSION", BaltimoreUserAgent.BALTIMORE_YOUTUBE_APP.getPackageVersion() },
			{ "SYSTEM_CUSTOM_REQUEST_PLATFORM", "android" },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "3" },
			{ "SYSTEM_IS_MOBILE_CONTEXT", "1" },
			{ "SYSTEM_CUSTOM_USER_AGENT", BaltimoreUserAgent.BALTIMORE_YOUTUBE_APP.generate() },
			{ "SYSTEM_FALLBACK_API_KEY", "AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w" },
			{ "SYSTEM_SEND_PARAM_OBJ", "1" } })),
	EMBEDDED_ANDROID("CLIENT_ANDROID_YT_EMBEDDED", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "ANDROID_EMBEDDED_PLAYER" },
			{ "SYSTEM_ENABLE_BALTIMORE_V1", BaltimoreType.YOUTUBE_APP.id() },
			{ "SYSTEM_FALLBACK_VERSION", BaltimoreUserAgent.BALTIMORE_YOUTUBE_APP.getPackageVersion() },
			{ "SYSTEM_CUSTOM_REQUEST_PLATFORM", "android" },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "55" },
			{ "SYSTEM_IS_MOBILE_CONTEXT", "1" },
			{ "SYSTEM_IS_EMBEDDED_CONTEXT", "1" },
			{ "SYSTEM_CUSTOM_USER_AGENT", BaltimoreUserAgent.BALTIMORE_YOUTUBE_APP.generate() },
			{ "SYSTEM_FALLBACK_API_KEY", "AIzaSyCjc_pVEDi4qsv5MtC2dMXzpIaDoRFLsxw" },
			{ "SYSTEM_SEND_PARAM_OBJ", "1" } })),
	ANDROID_YT_MUSIC("CLIENT_ANDROID_YT_MUSIC", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "ANDROID_MUSIC" },
			{ "SYSTEM_ENABLE_BALTIMORE_V1", BaltimoreType.YOUTUBE_MUSIC_APP.id() },
			{ "SYSTEM_FALLBACK_VERSION", BaltimoreUserAgent.BALTIMORE_YOUTUBE_MUSIC_APP.getPackageVersion() },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "21" },
			{ "SYSTEM_CUSTOM_HOST", "music.youtube.com" },
			{ "SYSTEM_FALLBACK_API_KEY", "AIzaSyAOghZGza2MQSZkY_zfZ370N-PUdXEo8AI" },
			{ "SYSTEM_IS_MOBILE_CONTEXT", "1" },
			{ "SYSTEM_CUSTOM_USER_AGENT", BaltimoreUserAgent.BALTIMORE_YOUTUBE_MUSIC_APP.generate() }, })),
	ANDROID_YT_CREATOR("CLIENT_ANDROID_YT_CREATORS", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "ANDROID_CREATOR" },
			{ "SYSTEM_ENABLE_BALTIMORE_V1", BaltimoreType.YOUTUBE_CREATORS_APP.id() },
			{ "SYSTEM_FALLBACK_VERSION", BaltimoreUserAgent.BALTIMORE_YOUTUBE_CREATORS_APP.getPackageVersion() },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "14" },
			{ "SYSTEM_REQUIRES_SAPI_HASH", "1" },
			{ "SYSTEM_IS_MOBILE_CONTEXT", "1" },
			{ "SYSTEM_CUSTOM_HOST", "www.youtube.com" },
			{ "SYSTEM_CUSTOM_USER_AGENT", BaltimoreUserAgent.BALTIMORE_YOUTUBE_CREATORS_APP.generate() },
			{ "SYSTEM_FALLBACK_API_KEY", "AIzaSyD_qjV8zaaUMehtLkrKFgVeSX_Iqbtyws8" } })),
	TVANDROID("CLIENT_TV_ANDROID", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "TVANDROID" },
			{ "SYSTEM_FALLBACK_VERSION", "1.0" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.android.apps.youtube/1.0 (Linux; U; Android 12; en_GB; Pixel 6 Build/GENTOO) gzip" }, })),
	ANDROID_TV("CLIENT_ANDROID_TV", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "ANDROID_TV" },
			{ "SYSTEM_FALLBACK_VERSION", "2.13" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.android.apps.youtube/2.13 (Linux; U; Android 12; en_GB; Pixel 6 Build/GENTOO) gzip" }, })),
	ANDROID_VR("CLIENT_ANDROID_VR", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "ANDROID_VR" },
			{ "SYSTEM_FALLBACK_VERSION", "0.1" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.android.apps.youtube/0.1 (Linux; U; Android 12; en_GB; Pixel 6 Build/GENTOO) gzip" }, })),
	ANDROID_UNPLUGGED("CLIENT_ANDROID_UNPLUGGED", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "ANDROID_UNPLUGGED" },
			{ "SYSTEM_FALLBACK_VERSION", "5.26.1" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.android.apps.youtube/5.26.1 (Linux; U; Android 12; en_GB; Pixel 6 Build/GENTOO) gzip" }, })),
	ANDROID_TESTSUITE("CLIENT_ANDROID_TESTSUITE", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "ANDROID_TESTSUITE" },
			{ "SYSTEM_FALLBACK_VERSION", "1.9" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.android.apps.youtube/1.9 (Linux; U; Android 12; en_GB; Pixel 6 Build/GENTOO) gzip" }, })),
	ANDROID_LITE("CLIENT_ANDROID_LITE", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "ANDROID_LITE" },
			{ "SYSTEM_FALLBACK_VERSION", "3.26.1" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.android.apps.youtube/3.26.1 (Linux; U; Android 12; en_GB; Pixel 6 Build/GENTOO) gzip" },
			{ "SYSTEM_SEND_PARAM_OBJ", "1" } })),
	TV_UNPLUGGED_ANDROID("CLIENT_TV_UNPLUGGED_ANDROID", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "TV_UNPLUGGED_ANDROID" },
			{ "SYSTEM_FALLBACK_VERSION", "0.1" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.android.apps.youtube/3.26.1 (Linux; U; Android 12; en_GB; Pixel 6 Build/GENTOO) gzip" }, })),

	/* iOS */

	iOS("CLIENT_IOS_YT", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "IOS" },
			{ "SYSTEM_FALLBACK_VERSION", IOS_CLIENT_VERSION },
			{ "SYSTEM_CUSTOM_DEVICE_MODEL", "iPhone14,3" },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "5" },
			{ "SYSTEM_IS_MOBILE_CONTEXT", "1" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.ios.youtube/" + IOS_CLIENT_VERSION + " (iPhone14,3; U; CPU iOS 15_2_1 like Mac OS X; en_GB)" },
			{ "SYSTEM_FALLBACK_API_KEY", "AIzaSyB-63vPrdThhKuerbB2N_l7Kwwcxj6yUAc" } })),
	EMBEDDED_iOS("CLIENT_IOS_YT_EMBEDDED", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "IOS_MESSAGES_EXTENSION" },
			{ "SYSTEM_FALLBACK_VERSION", IOS_CLIENT_VERSION },
			{ "SYSTEM_CUSTOM_DEVICE_MODEL", "iPhone14,3" },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "66" },
			{ "SYSTEM_IS_MOBILE_CONTEXT", "1" },
			{ "SYSTEM_IS_EMBEDDED_CONTEXT", "1" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.ios.youtube/" + IOS_CLIENT_VERSION + " (iPhone14,3; U; CPU iOS 15_2_1 like Mac OS X; en_GB)" } })),
	IOS_LIVE_CREATION_EXTENSION("CLIENT_IOS_LIVE_CREATION_EXTENSION", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "IOS_LIVE_CREATION_EXTENSION" },
			{ "SYSTEM_FALLBACK_VERSION", IOS_CLIENT_VERSION },
			{ "SYSTEM_CUSTOM_DEVICE_MODEL", "iPhone14,3" },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "66" },
			{ "SYSTEM_IS_MOBILE_CONTEXT", "1" },
			{ "SYSTEM_IS_EMBEDDED_CONTEXT", "1" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.ios.youtube/" + IOS_CLIENT_VERSION + " (iPhone14,3; U; CPU iOS 15_2_1 like Mac OS X; en_GB)" } })),
	iOS_YT_MUSIC("CLIENT_IOS_YT_MUSIC", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "IOS_MUSIC" },
			{ "SYSTEM_FALLBACK_VERSION", IOS_MUSIC_CLIENT_VERSION },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "26" },
			{ "SYSTEM_CUSTOM_HOST", "music.youtube.com" },
			{ "SYSTEM_FALLBACK_API_KEY", "AIzaSyBAETezhkwP0ZWA02RsqT1zu78Fpt0bC_s" },
			{ "SYSTEM_IS_MOBILE_CONTEXT", "1" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.ios.youtube/" + IOS_MUSIC_CLIENT_VERSION + " (iPhone14,3; U; CPU iOS 15_2_1 like Mac OS X; en_GB)" } })),
	iOS_YT_CREATOR("CLIENT_IOS_YT_CREATORS", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "IOS_CREATOR" },
			{ "SYSTEM_FALLBACK_VERSION", IOS_CREATOR_CLIENT_VERSION },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "15" },
			{ "SYSTEM_REQUIRES_SAPI_HASH", "1" },
			{ "SYSTEM_IS_MOBILE_CONTEXT", "1" },
			{ "SYSTEM_CUSTOM_HOST", "www.youtube.com" },
			{ "SYSTEM_CUSTOM_USER_AGENT",
					"com.google.ios.youtube/" + IOS_CREATOR_CLIENT_VERSION + " (iPhone14,3; U; CPU iOS 15_2_1 like Mac OS X; en_GB)" } })),
	TVAPPLE("CLIENT_TV_APPLE", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "TVAPPLE" },
			{ "SYSTEM_FALLBACK_VERSION", "1.0" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.ios.youtube/1.0 (iPhone14,3; U; CPU iOS 15_2_1 like Mac OS X; en_GB)" } })),
	iOS_UNPLUGGED("CLIENT_IOS_UNPLUGGED", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "IOS_UNPLUGGED" },
			{ "SYSTEM_FALLBACK_VERSION", "5.26.1" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.ios.youtube/5.26.1 (iPhone14,3; U; CPU iOS 15_2_1 like Mac OS X; en_GB)" } })),
	iOS_EMBEDDED_PLAYER("CLIENT_IOS_EMBEDDED_PLAYER", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "IOS_UNPLUGGED" },
			{ "SYSTEM_FALLBACK_VERSION", "2.0" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.ios.youtube/2.0 (iPhone14,3; U; CPU iOS 15_2_1 like Mac OS X; en_GB)" } })),
	iOS_UPTIME("CLIENT_IOS_UPTIME", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "IOS_UPTIME" },
			{ "SYSTEM_FALLBACK_VERSION", "1.0" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.ios.youtube/2.0 (iPhone14,3; U; CPU iOS 15_2_1 like Mac OS X; en_GB)" } })),
	iOS_PRODUCER("CLIENT_IOS_PRODUCER", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "IOS_PRODUCER" },
			{ "SYSTEM_FALLBACK_VERSION", "0.1" },
			{ "SYSTEM_CUSTOM_USER_AGENT", "com.google.ios.youtube/2.0 (iPhone14,3; U; CPU iOS 15_2_1 like Mac OS X; en_GB)" } })),

	/* Others */

	MOBILE_WEB("CLIENT_MOBILE_WEB", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "MWEB" },
			{ "SYSTEM_FALLBACK_VERSION", "2.20220801.00.00" },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "2" },
			{ "SYSTEM_FALLBACK_API_KEY", "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8" },
			{ "SYSTEM_IS_MOBILE_CONTEXT", "1" },
			{ "SYSTEM_CUSTOM_USER_AGENT",
					"Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/" + URLUtils.USER_AGENT_VERSION
							+ " Mobile Safari/537.36" } })),
	MOBILE_WEB_TIER2("CLIENT_MOBILE_WEB_TIER_2", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "MWEB_TIER_2" },
			{ "SYSTEM_FALLBACK_VERSION", "9.20220325" },
			{ "SYSTEM_FALLBACK_API_KEY", "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8" },
			{ "SYSTEM_IS_MOBILE_CONTEXT", "1" },
			{ "SYSTEM_CUSTOM_USER_AGENT",
					"Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/" + URLUtils.USER_AGENT_VERSION
							+ " Mobile Safari/537.36" } })),

	TVHTML5_SIMPLE_EMBEDDED_PLAYER("CLIENT_TV_HTML5_SIMPLY_EMBEDDED_PLAYER", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "TVHTML5_SIMPLY_EMBEDDED_PLAYER" },
			{ "SYSTEM_FALLBACK_VERSION", "2.0" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" }, })),
	TVHTML5("CLIENT_TV_HTML5", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "TVHTML5" },
			{ "SYSTEM_FALLBACK_VERSION", "7.20220325" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" }, })),
	TVLITE("CLIENT_TV_LITE", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "TVLITE" },
			{ "SYSTEM_FALLBACK_VERSION", "2" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" }, })),
	TVHTML5_CAST("CLIENT_TV_HTML5_CAST", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "TVHTML5_CAST" },
			{ "SYSTEM_FALLBACK_VERSION", "1.1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" }, })),
	TV_UNPLUGGED_CAST("CLIENT_TV_UNPLUGGED_CAST", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "TV_UNPLUGGED_CAST" },
			{ "SYSTEM_FALLBACK_VERSION", "0.1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" }, })),
	TVHTML5_UNPLUGGED("CLIENT_TV_HTML5_UNPLUGGED", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "TVHTML5_UNPLUGGED" },
			{ "SYSTEM_FALLBACK_VERSION", "5.26.1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" }, })),
	TVHTML5_VR("CLIENT_TV_HTML5_VR", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "TVHTML5_VR" },
			{ "SYSTEM_FALLBACK_VERSION", "0.1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" }, })),
	TVHTML5_YONGLE("CLIENT_TV_HTML5_YONGLE", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "TVHTML5_YONGLE" },
			{ "SYSTEM_FALLBACK_VERSION", "0.1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" }, })),
	TVHTML5_SIMPLY("CLIENT_TV_HTML5_SIMPLY", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "TVHTML5_SIMPLY" },
			{ "SYSTEM_FALLBACK_VERSION", "1.0" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" }, })),
	TVHTML5_FOR_KIDS("CLIENT_TV_HTML5_FOR_KIDS", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "TVHTML5_FOR_KIDS" },
			{ "SYSTEM_FALLBACK_VERSION", "7.20220325" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" }, })),

	GOOGLE_ASSISTANT("CLIENT_GOOGLE_ASSISTANT", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "GOOGLE_ASSISTANT" },
			{ "SYSTEM_FALLBACK_VERSION", "0.1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" }, })),
	GOOGLE_MEDIA_ACTIONS("CLIENT_GOOGLE_MEDIA_ACTIONS", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "GOOGLE_MEDIA_ACTIONS" },
			{ "SYSTEM_FALLBACK_VERSION", "0.1" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" }, })),

	XBOXONEGUIDE("CLIENT_XBOX_ONE_GUIDE", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "XBOXONEGUIDE" },
			{ "SYSTEM_FALLBACK_VERSION", "1.0" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" }, })),

	/* Provides a muxed 1080p stream, probably a life saver for legacy users */
	MEDIA_CONNECT_FRONTEND("MEDIA_CONNECT_FRONTEND", fixedUniMap(new Object[][]
	{
			{ "SYSTEM_CLIENT_NAME", "MEDIA_CONNECT_FRONTEND" },
			{ "SYSTEM_CONTEXT_CLIENT_NAME", "95" },
			{ "SYSTEM_FALLBACK_VERSION", "1.0" },
			{ "SYSTEM_ENABLE_V9_CIPHER_DECODE", "1" } }))

	;

	private final Map<String, String> metadata;
	public final String id;

	private YTIAPIClientType(final String id, final Map<String, String> metadata) {
		this.id = id;
		this.metadata = Collections.unmodifiableMap(metadata);
	}

	public String getID() {
		return this.id;
	}

	public Map<String, String> getMetadata() {
		return this.metadata;
	}

	public String get(final YTIAPIClientEnums type) {
		return this.metadata.get(type.mapKey);
	}

	public String get(final String type) {
		return this.metadata.get(type);
	}

	public String getOrDefault(final String type, final String fallback) {
		return this.metadata.getOrDefault(type, fallback);
	}

	public boolean contains(final YTIAPIClientEnums type) {
		return this.metadata.containsKey(type.mapKey);
	}

	public boolean contains(final String type) {
		return this.metadata.containsKey(type);
	}

	public static YTIAPIClientType getFromID(final String id) {
		for (final YTIAPIClientType type : values())
			if (type.id.equalsIgnoreCase(id))
				return type;
		return null;
	}

	public static enum YTIAPIClientEnums {
		ClientName("SYSTEM_CLIENT_NAME"),
		FallbackVersion("SYSTEM_FALLBACK_VERSION"),
		ContextClientName("SYSTEM_CONTEXT_CLIENT_NAME"),
		CustomHostHeader("SYSTEM_CUSTOM_HOST"),
		FallbackAPIKey("SYSTEM_FALLBACK_API_KEY"),
		RequiresSAPISID("SYSTEM_REQUIRES_SAPI_HASH"),
		CustomUserAgent("SYSTEM_CUSTOM_USER_AGENT"),
		IsMobileContext("SYSTEM_IS_MOBILE_CONTEXT"),
		IsEmbeddedContext("SYSTEM_IS_EMBEDDED_CONTEXT"),
		SuggestsV9Cipher("SYSTEM_ENABLE_V9_CIPHER_DECODE"),
		OSName("SYSTEM_OS_NAME"),
		SystemSendParamObj("SYSTEM_SEND_PARAM_OBJ"),
		DisableBrowserVersion("SYSTEM_NO_BROWSER_VERSION"),
		CustomRequestPlatform("SYSTEM_CUSTOM_REQUEST_PLATFORM"),
		EnableBaltimore("SYSTEM_ENABLE_BALTIMORE_V1"),

		;

		private final String mapKey;

		private YTIAPIClientEnums(final String mapKey) {
			this.mapKey = mapKey;
		}

		public String getMapKey() {
			return this.mapKey;
		}
	}

	public static String getClientVersion(final YTIAPIClientType clientType) {
		switch (clientType) {
			case WEB:
			case MOBILE_WEB:
				return YouTubeExtractorConstants.CLIENT_VERSION;
			/* TODO: Implement YTEClientDateGenerator for once... */
			default:
				return clientType.get(YTIAPIClientEnums.FallbackVersion);
		}
	}
}
